{
memset(p2m, 0, sizeof(*p2m));
mm_lock_init(&p2m->lock);
+ INIT_LIST_HEAD(&p2m->np2m_list);
INIT_PAGE_LIST_HEAD(&p2m->pages);
INIT_PAGE_LIST_HEAD(&p2m->pod.super);
INIT_PAGE_LIST_HEAD(&p2m->pod.single);
return -ENOMEM;
p2m_initialise(d, p2m);
p2m->write_p2m_entry = nestedp2m_write_p2m_entry;
+ list_add(&p2m->np2m_list, &p2m_get_hostp2m(d)->np2m_list);
}
return 0;
static struct p2m_domain *
p2m_getlru_nestedp2m(struct domain *d, struct p2m_domain *p2m)
{
- int i, lru_index = -1;
- struct p2m_domain *lrup2m, *tmp;
-
- if (p2m == NULL) {
- lru_index = MAX_NESTEDP2M - 1;
- lrup2m = d->arch.nested_p2m[lru_index];
- } else {
- lrup2m = p2m;
- for (i = 0; i < MAX_NESTEDP2M; i++) {
- if (d->arch.nested_p2m[i] == p2m) {
- lru_index = i;
- break;
- }
- }
- }
-
- ASSERT(lru_index >= 0);
- if (lru_index == 0) {
- return lrup2m;
- }
+ struct list_head *lru_list = &p2m_get_hostp2m(d)->np2m_list;
+
+ ASSERT(!list_empty(lru_list));
- /* move the other's down the array "list" */
- for (i = lru_index - 1; i >= 0; i--) {
- tmp = d->arch.nested_p2m[i];
- d->arch.nested_p2m[i+1] = tmp;
- }
+ if ( p2m == NULL )
+ p2m = list_entry(lru_list->prev, struct p2m_domain, np2m_list);
- /* make the entry the first one */
- d->arch.nested_p2m[0] = lrup2m;
+ list_move(&p2m->np2m_list, lru_list);
- return lrup2m;
+ return p2m;
}
/* Reset this p2m table to be empty */
#define CR3_EADDR (~0ULL)
uint64_t cr3;
+ /* Nested p2ms: linked list of n2pms allocated to this domain.
+ * The host p2m hasolds the head of the list and the np2ms are
+ * threaded on in LRU order. */
+ struct list_head np2m_list;
+
+
/* Host p2m: when this flag is set, don't flush all the nested-p2m
* tables on every host-p2m change. The setter of this flag
* is responsible for performing the full flush before releasing the